package fzu.functiongather.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import fzu.functiongather.R;

/**
 * Created by RuiyuHuang on 2016/7/15 0015.
 */
public class DrawerMenuAdapter extends BaseAdapter {

    private List<String> drawerMenuList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public DrawerMenuAdapter(List<String> drawerMenuList, Context mContext) {
        this.drawerMenuList = drawerMenuList;
        this.mContext = mContext;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return drawerMenuList.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Object getItem(int position) {
        return drawerMenuList.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {
            //根据布局文件获取View返回值
            convertView = LayoutInflater.from(mContext).inflate(R.layout.drawer_menu_item,null);
            holder = new ViewHolder();
            holder.tv_drawer_menu_item = (TextView) convertView.findViewById(R.id.tv_drawer_menu_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.tv_drawer_menu_item.setText(drawerMenuList.get(position).toString());
        return  convertView;
    }

    protected class ViewHolder {
        protected TextView tv_drawer_menu_item;
    }
}
